// Copyright (c) 2021 Presto Labs Pte. Ltd.
// Author: gekim

#pragma once

#include <map>
#include <memory>
#include <regex>
#include <string>
#include <vector>

// internal
#include "coin2/exchange/base/feed/processor.h"
#include "coin2/exchange/base/market/enums.h"
#include "coin2/exchange/di/constant.h"

namespace coin2::exchange::bitbank::feed_v1 {
namespace impl {
using namespace coin2::exchange::base::symbology;
class BitbankFeedProcessor : public base::feed::FeedParsingProcessor {
 public:
  explicit BitbankFeedProcessor(
      const std::string& system_name,
      const coin2::exchange::di::ConstantInjection& ci,
      const feed::RawParserConfig& config)
      : FeedParsingProcessor(
            system_name,
            MarketExchangeApi{MarketType::Spot, ExchangeType::Bitbank, "v1"},
            ci,
            config,
            "cc/coin2/exchange/bitbank/feed_v1/schema.json") {}
  void OnTopicRecord(const base::executor::TopicRecordPacket& packet) override;
};
struct BitbankChannel {
  std::string channel;
  std::string native_symbol;

  static BitbankChannel Parse(const std::string& channel) {
    /*
      channels.book_snapshot = '"depth_whole_{}"'
      channels.book_diff = '"depth_diff_{}"'
      channels.trade = '"transactions_{}"'
    */

    const std::vector<std::string> CHANNEL_HEADERS = {"depth_whole", "depth_diff", "transactions"};
    for (auto& channel_header : CHANNEL_HEADERS) {
      if (channel.find(channel_header + "_") == 0) {
        return BitbankChannel{channel_header, channel.substr(channel_header.length()+1)};
      }
    }

    THROW() << "unknown channel: " << channel;
    return BitbankChannel{};
  }
};
};  // namespace impl
using impl::BitbankChannel;
using impl::BitbankFeedProcessor;
}  // namespace coin2::exchange::bitbank::feed_v1
